package com.example.chenfenweb.config;

import com.example.chenfenweb.entity.SysTemplateManager;
import com.example.chenfenweb.service.ISysTemplateManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private ISysTemplateManagerService sysTemplateManagerService;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        List<SysTemplateManager> templeList = sysTemplateManagerService.list();
        templeList.stream().forEach(item->{
            if(item.getTemplateStatus().equals("1")){
                registry.addResourceHandler("/"+item.getTemplatePath()+"/**")
                        .addResourceLocations("file:///D:/opt/"+item.getTemplatePath()+"/");
            }else{
                registry.addResourceHandler("/"+item.getTemplatePath()+"/**")
                        .addResourceLocations("file:///D:/opt/"+item.getTemplatePath()+"/");
            }
        });
    }

}
